<template>
  <div>
    <div>
      <Button
        style="margin-top: 10px"
        type="primary"
        @click="close"
      >返回</Button>
    </div>
    <br>
    <EditForm
      :infos="infos"
      @submit="submit"
      ref="edit"
      style="width: 50%;margin: 10px auto;"
    />
  </div>
</template>

<script>
import EditForm from './../../EditForm/index.vue'
export default {
  components: {
    EditForm
  },
  data() {
    return {
      infos: [
        {
          label: '分类名称',
          value: '',
          key: 'name',
          rules: true,
          colSpan: 24
        }
      ]
    }
  },
  methods: {
    async submit(v) {
      if (v) {
        this.$http.createCategory(v)
          .then(res => {
            if (res) {
              this.$message({
                type: 'success',
                message: '新增分类成功!'
              })
              this.close()
              this.$emit('update')
            }
          })
          .catch(err => {
            console.log('新增分类失败！')
            this.$message({
              type: 'error',
              message: '新增分类失败!'
            })
          })
      }
    },
    close() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped>
</style>
